package com.yanqu.road.server.cmd;

import com.yanqu.road.connect.AgentServerLinkControl;
import com.yanqu.road.player.Player;
import com.yanqu.road.player.PlayerControl;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

@Cmd(code = Protocol.A_DISPERSE_GOLD_TRANSFER, desc = "世界消息转发")
public class DisperseGoldTransferCmd implements Command {

	@Override
	public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
		Map<Long, Player> allPlayer = new HashMap<>(PlayerControl.getOnlinePlayerMap());
		for (Entry<Long, Player> dataEntry : allPlayer.entrySet()) {
			YanQuMessage msg = YanQuMessageUtils.buildMessageByte(Protocol.U_DISPERSEGOLD_FIND_GOD, packet.getBytes());
			msg.setPlayerId(dataEntry.getKey());
			msg.setLen(packet.getLen());
			AgentServerLinkControl.routeClient(msg);
		}
	}
}